/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Lab4_Homework;

import java.util.Scanner;

/**
 *
 * @author THIEN
 */
public class Supermarket_implements implements Supermarket{

    int id,i;
    float price;

//contructor

    public Supermarket_implements() {
    }

    public Supermarket_implements(int id, float price) {
        this.id = id;
        this.price = price;
    }
    Supermarket_implements[] SD = new Supermarket_implements[4];
//override view method
    public void view()
    {       
        for(int i =0;i<4;i++)
        {
             SD[i] = new Supermarket_implements(id=(i+1),price=(1000*i));
             System.out.println("Product ID ="+id+" has the name is and the price of it is: "+price);
        }
    }
//override compare method
    public void compare()
    {
        int i,j,p1,p2;
        Scanner scan = new Scanner(System.in);
        System.out.print("\nPlz choose the first product ID: ");
        p1 = Integer.parseInt(scan.nextLine());
        System.out.print("\nPlz choose the second product ID: ");
        p2 = Integer.parseInt(scan.nextLine());
//create array
        for(i =0,j=0;i<4;i++,j++)
        {
             SD[i] = new Supermarket_implements(id=(i+1),price=(1000*i));
             SD[j] = new Supermarket_implements(id=(j+1),price=(1000*j));
        }
//starting compare
        if(p1==p2)
        {
            System.out.println("********************* 2 product ID must not have a same *********************");

        }
        else
        {
            if(0<p1 && p1<=4 && 0<p2 && p2<=4)
            {
                if(SD[p1-1].price > SD[p2-1].price)
                {
                    System.out.println("Product 2 is cheaper than Product 1");
                }
                else if(SD[p1-1].price == SD[p2-1].price)
                {
                     System.out.println("2 Products are equal price ");
                }
                else
                {
                     System.out.println("Product 1 is cheaper than Product 2");
                }
            }
            else
                System.out.println("********************** Your product ID is invalid !*********************");

     
        }
                
    }
//set and get
    public void setID(int id)
    {
        this.id = id;
    }
    public void setPrice(float price)
    {
        this.price = price;
    }
    public int getID()
    {
        return id;
    }
    public float getPrice()
    {
        return price;
    }

}
